package com.stormrage.edu.serv.edu.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.stormrage.edu.dao.edu.EduModuleDao;
import com.stormrage.edu.serv.edu.EduCourseServ;
import com.stormrage.edu.serv.edu.EduModuleServ;
import com.stormrage.edu.serv.learn.LeaTermServ;
import com.stormrage.entity.edu.EduModule;
import com.stormrage.entity.edu.rep.EduModuleRep;
import com.stormrage.entity.learn.LeaTerm;
import com.stormrage.entity.learn.rep.LeaCourseStudyRep;
import com.stormrage.entity.learn.req.LeaCourseStudyReq;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @author www.stormragetech.com
 * @date 2016年1月19日
 * @version 1.0.0
 */
@Service
public class EduModuleServImpl implements EduModuleServ {

	private static final Logger logger = LoggerFactory.getLogger(EduModuleServImpl.class);

	@Autowired
	private EduCourseServ eduCourseServ;

	@Autowired
	private LeaTermServ leaTermServ;

	@Autowired
	private EduModuleDao eduModuleDao;

	@Override
	public List<EduModuleRep> queryRepListByMajorId(final LeaCourseStudyReq arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 EduModuleServ 】- 【 QueryRepListById 】- 开始运行 ");

		LeaTerm term = leaTermServ.queryById(arg0.getTermId());

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", term.getMajorId());

		List<EduModuleRep> array = eduModuleDao.queryRepListByMajorId(map);
		int seq = 1;

		Iterator<EduModuleRep> it = array.iterator();
		while (it.hasNext()) {
			EduModuleRep entity = it.next();
			List<LeaCourseStudyRep> course = eduCourseServ.queryStudyRepListByMajorId(arg0);
			entity = EduModuleRep.instance(entity, seq, course);
			seq++;
		}

		logger.debug(" 【 Serv 】- 【 EduModuleServ 】- 【 QueryRepListById 】- 完成运行 ");
		return array;

	}

	@Override
	public List<EduModule> queryListByMajorNess(final LeaCourseStudyReq arg0) throws StormrageTechException {

		logger.debug(" 【 Serv 】- 【 EduModuleServ 】- 【 queryListByMajorNess 】- 开始运行 ");

		LeaTerm term = leaTermServ.queryById(arg0.getTermId());

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", term.getMajorId());
		map.put("ness", arg0.getNess());

		List<EduModule> array = eduModuleDao.queryListByMajorNess(map);

		logger.debug(" 【 Serv 】- 【 EduModuleServ 】- 【 queryListByMajorNess 】- 完成运行 ");
		return array;

	}

}
